package interview.questions.从尾到头打印列表;

public class ListNode {

    public int val;

    public ListNode next = null;

    public ListNode() {

    }

    /**
     * 指针
     *
     * @param val 指针
     */
    public ListNode(int val) {

        this.val = val;

    }

    public void setNext(ListNode next) {
        this.next = next;
    }

    public ListNode getNext() {
        return next;
    }

    public int getData() {
        return val;
    }

    public static void getDataByLoop(ListNode node) {
        while (node != null) {
            System.out.print(node.getData()+"\t");
            node = node.getNext();
        }
    }

    public static void getDataByRecursion(ListNode node) {
        if (node == null) {
            return;
        }
        System.out.print(node.getData()+"\t");
        getDataByRecursion(node.getNext());
    }


}